package xyz.flowlight.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import xyz.flowlight.domain.entity.Cart;

import java.util.List;

@Mapper
public interface CartMapper extends BaseMapper<Cart> {
    // 根据用户ID查询购物车所有商品
    @Select("SELECT * FROM cart WHERE user_id = #{userId}")
    List<Cart> findByUser(@Param("userId") Integer userId);

    // 根据用户ID和商品ID查询购物车项
    @Select("SELECT * FROM cart WHERE user_id = #{userId} AND product_id = #{productId}")
    Cart findByUserAndProduct(
            @Param("userId") Integer userId,
            @Param("productId") Integer productId
    );



    Cart findByUserIdAndProductId(@Param("userId") Integer userId, @Param("productId") Integer productId);
}
